<?php
namespace app\wechat\controller;


use app\wechat\model\Custom;
use app\wechat\model\Event;
use EasyWeChat\Foundation\Application;

/**
 * 微信接入交互类
 * User: PunkVv<punkv@qq.com>
 * Class Index
 * @package app\wechat\controller
 */
class Index
{
    public function index()
    {
        $options = get_wechat_option();
        //初始化
        $app = new Application($options);

        $server = $app->server;

        $server->setMessageHandler(function ($message) {
            switch ($message->MsgType) {
                case 'event':
                    # 事件...
                    new Event($message);
                    break;
                default:
                    # 消息...
                    new Custom($message);
                    break;
            }
        });

        $response = $server->serve();

        //将响应输出
        $response->send();
    }
}
